<template>
    <div id="auth-login">
        <Row>
            <Col :xs="{ span: 18, offset: 3 }" :md="{ span: 12, offset: 6 }" :lg="{ span: 6, offset: 9 }">
                <h2 class="login-header"><img src="/statics/console/img/logo.png" width="170" alt=""></h2>
                <Alert type="success">自动登陆中，请耐心等待……</Alert>
            </Col>
        </Row>
    </div>
</template>

<script>
import CryptoJS from 'crypto-js'
import tenant_router from '../.././router/tenant'
import { LOGIN } from '../.././store/mutation_types'
export default {
    name: 'AuthLogin',
    data() {
        return {
            aes_iv : "lLBvDbxgqUStnz87",
            aes_key : "d22icaUY3o9NpQM0",
        }
    },
    mounted: function() {
        // dttxBatpRleOwD%2BAFtm%2BX3N7bfDRq0J4WL4Y7p9vP9rlvckZUs%2B6OU8k%2BKmr26S%2BFGk7RRyIK7firKwUenY59A%3D%3D
        // this.$route.query.param
        try {
            var param = this.$route.query.param;
            console.log(param)
            var jsonStr = JSON.parse(this.aes_decrypt(param));
            console.log(jsonStr)
            this.$store.commit(LOGIN, jsonStr)
            console.log(localStorage.getItem('ttoken'))
            tenant_router.push('/index/index');
        } catch (error) {
            console.log(error)
            // alert('参数错误了');
        }
    },
    methods: {
        // 加密
        aes_encrypt(str) {
            var key = CryptoJS.enc.Utf8.parse(this.aes_key);
            var iv = CryptoJS.enc.Utf8.parse(this.aes_iv);
            var encrypted = CryptoJS.AES.encrypt(str, key, {
                iv: iv,
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7
            }).toString();
            return encrypted;
        },
        //解密
        aes_decrypt(str) {
            var key = CryptoJS.enc.Utf8.parse(this.aes_key);
            var iv = CryptoJS.enc.Utf8.parse(this.aes_iv);
            var decrypt = CryptoJS.AES.decrypt(str, key, {
                iv: iv,
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7
            });
            return decrypt.toString(CryptoJS.enc.Utf8);
        }
    }
}
</script>
